//
// Created by 高森森 on 2022/10/16.
//

#ifndef LEETCODE_SOLUTION_27_H
#define LEETCODE_SOLUTION_27_H
#include<bits/stdc++.h>
using namespace std;

class solution_27 {
public:
    vector<vector<int>>sums;
    solution_27(vector<vector<int>>& matrix) {
        int row=matrix.size();
        int col=matrix[0].size();
        sums.resize(row+1,vector<int>(col+1,0));
        //预处理
        for(int i=1;i<=row;i++)
            for(int j=1;j<=col;j++){
                sums[i][j]=sums[i-1][j]+sums[i][j-1]-sums[i-1][j-1]+matrix[i-1][j-1];
            }
    }

    int sumRegion(int row1, int col1, int row2, int col2) {
        row1+=1;
        col1+=1;
        row2+=1;
        col2+=1;
        return sums[row2][col2]-sums[row1-1][col2]-sums[row2][col1-1]+sums[row1-1][row1-1];
    }
};


#endif //LEETCODE_SOLUTION_27_H
